package com.sunchangming.stmdb;

import java.nio.file.Files;
import java.nio.file.Paths;

import org.junit.AfterClass;
import org.junit.BeforeClass;

import com.sunchangming.stmdb.btree.BTree;

public class TestBtree {
	private static BTree tree;
	private static RecordManager recman;
	private static java.nio.file.Path dir;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		dir = Paths.get("TestBtree");
		TestUtil.deleteDir(dir);
		Files.createDirectory(dir);
		recman = RecordManagerProvider.createRecordManager(dir.resolve("test").toString(), false, 1000);

		final long recid = recman.getNamedObject("main");
		if (recid != 0) {
			tree = BTree.load(recman, recid);
		} else {
			tree = BTree.createInstance(recman);
			recman.setNamedObject("main", tree.getRecid());
		}

	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		recman.close();
		TestUtil.deleteDir(dir);
	}

}
